package homework.level01model03.homework04;

import com.sun.deploy.panel.AbstractRadioPropertyGroup;

import java.io.*;
import java.util.ArrayList;

public class StudentRead {
    /*

        当系统启动时读取文件中所 有学生信息到 List 集合中。
    */
    public static ArrayList<Student> read(String url){

        ObjectInputStream ois = null;
        ArrayList<Student> obj1 = null;

        try {
            // 创建对象流

            ois = new ObjectInputStream(new FileInputStream("G:\\IdeaProjects\\javase\\src\\homework\\level01model03\\homework04\\homework05.txt"));

            System.out.println(ois);
            // 2.指定文本中读取集合对象

            Object obj = ois.readObject();
            System.out.println(obj);
            obj1 = (ArrayList<Student>) obj;
            System.out.println("读取到的对象是：" + obj);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            // 3.关闭流对象并释放有关的资源
            if (null != ois) {
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

        return obj1;
    }

}
